package Test7;

import java.io.*;

public class Test7 {
    public static void main(String[] args) {
        // 记录开始时间
        long startTime = System.currentTimeMillis();

        // 使用匿名内部类方式开启线程
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 源文件路径和目标文件路径
                String srcPath = "kaoshi\\src\\Test7\\a.txt";
                String destPath = "copy_a.txt";

                try (
                        BufferedReader br = new BufferedReader(new FileReader(srcPath));
                        BufferedWriter bw = new BufferedWriter(new FileWriter(destPath))
                ) {
                    String line;
                    while ((line = br.readLine()) != null) {
                        bw.write(line);
                        bw.newLine();
                        bw.flush();
                    }
                    System.out.println("复制完毕");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        // 等待线程结束
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 记录结束时间
        long endTime = System.currentTimeMillis();

        // 计算并打印耗时
        System.out.println("复制完毕耗时:" + (endTime - startTime) + "毫秒");
    }

}
